<script type="text/javascript">
	 selectTab('view_entries');
</script>

<?php if($this->is_allow_view || $this->is_allow_vote_view || $this->contest->isEnd()):?>
    <?php if($this->isDisplaySearch):?>
        <div id="search_form" class="search_form">
            <?php echo $this->form;?>
			<?php echo $this->partial('index/_sortControl.phtml',array('query' => $this->pageValues, 'default_sort' => $this->contest->getViewEntriesDefault())) ?>
        </div>
    <?php endif;?>
    <?php if (Core_Util::hasMessage($this->contest->getThanksYouMgsKey())): ?>
        <div class="sm_message_panel">
            <p class="header">
                <?php echo $this->escape(Core_Util::getLatestMessage($this->contest->getThanksYouMgsKey())); ?>
            </p>
        </div>
    <?php endif; ?>
	<?php if (Core_Util::hasMessage('404')): ?>
        <div class="sm_message_panel">
            <p class="header">
                <?php echo $this->escape(Core_Util::getLatestMessage('404')); ?>
            </p>
        </div>
    <?php endif; ?>

    <?php if (!empty($this->messages)): ?>
        <div class="sm_message_panel">
            <?php foreach ($this->messages as $value) :?>
            <p class="header">
                <?php echo $this->translate($value); ?>
            </p>
            <?php endforeach;?>
        </div>
    <?php endif; ?>

	<?php if(count($this->paginator)): ?>
		<?php $i = 1; ?>
		<div class="entries_wrapper">
			<ul class="sm_grid_layout">
				<?php foreach($this->paginator as $index =>$entry): ?>
					<li class="nth_<?php echo $index % 4;?>">
						<a href="<?php echo $this->pageUrl(array_merge(array('target' => 'detail', 'id_entry' => $entry->id), $this->extraValues)); ?>">
							<img class="pic_item" src="<?php echo $entry->getThumbnailImageUrl() ?>"
								 title="<?php echo $this->escape($entry->title); ?>"/>
						</a>
						<div class="view_detail">
							<div class="ellipsis title">
                                <a href="<?php echo $this->pageUrl(array_merge(array('target' => 'detail', 'id_entry' => $entry->id), $this->extraValues)); ?>">
                                    <?php echo $this->escape($entry->title); ?>
                                </a>
                            </div>
							<div class="ellipsis">
                                <label>by </label>
                                <a target="_blank" href="<?php echo $entry->getLink();?>" title="<?php echo $this->escape($entry->getFullname());?>">
									<?php echo $this->escape($entry->getFullname());?>
								</a>
							</div>
							<div class="vote_number"><?php echo $this->number($entry->votes,'LABEL_NUM_VOTE'); ?></div>
						</div>
					</li>
				<?php endforeach; ?>
			</ul>
		</div>
	<?php elseif(!empty($this->extraValues['keyword'])):?>
		<div class="sm_message_panel" style="clear: both">
			<p class="header"><?php echo $this->translate('MSG_HAVE_NO_ENTRY_MATCH_YOUR_SEARCH');?></p>
		</div>
	<?php else:?>
		<div class="sm_message_panel">
			<p class="header"><?php echo $this->translate('MSG_HAVE_NO_ENTRY_YET');?></p>
		</div>
	<?php endif; ?>
	<?php
        if($this->sort != Core_Model_DbTable_Entries::ENTRIES_RANDOM):
            echo $this->paginationControl($this->paginator, 'Sliding', 'paginatorControl.phtml', array(
                'pageAsQuery' => true,
                'query' => $this->pageValues));
        else:
            echo $this->partial('randomControl.phtml', array('query' => $this->pageValues, 'arrListItemsCount' => $this->arrListItemsCount));
        endif;
	?>
<?php else:?>
	<div class="sm_message_panel">
        <?php if($this->contest->isWaiting()):?>
        <p class="header"><?php echo sprintf($this->translate('MSG_YOU_CAN_JOIN_AT'), $this->contest->getStartDate($this->translate('DATE_FORMAT')));?></p>
        <?php else:?>
        <p class="header"><?php echo $this->translate('MSG_DOES_NOT_ALLOW_VIEW_PHASE');?></p>
        <?php endif;?>
	</div>
<?php endif; ?>

<!-- Share to another social networks -->
<?php    
    $furl = $this->social->getShareUrl('/contest/share/contest/id_page/'.$this->social->getIdPage().'/id_contest/'.$this->contest->id);    
    $url = $this->contest->getShareUrlSocialNetworks(array(), FALSE);
    $url_facebook = $this->contest->getShareUrlSocialNetworks(array(), TRUE);
    preg_match_all('/(http:.*?\.com\/.*?\/)/', $furl,$matches);
    $durl = $matches[1][0].$this->pageUrl();
?>

 <div class="like-another-social-networks">
    <?php
        $info = $this->contest->getSharedContent($this->id_page);
    ?>
    <?php echo $this->partial('like-to-social-networks.phtml', array(
        'url'			=> $url,
        'url_facebook'	=> $url_facebook,        
        'id_page'       => $this->id_page,
        'id_user'		=> $this->id_user?$this->id_user:ID_USER_CHEAT_FOR_COUNT_SHARE,
        'show_text'		=> true,
        'message'		=> YouNet_Util::escapeForJs(sprintf($this->translate('REQUEST_MESSAGE'), $this->contest->title, $this->contest->getPageName($this->id_page))),
        'send'			=> false,
        'show_faces'	=> false,
        'show_fb_like'	=> false,
        'page_url'      => $_SERVER['HTTP_HOST'].$this->pageUrl(),
        'title'         => $info['title'],
        'img'           => $this->shareRow->getShareImage()
    ));?>
</div>
<div class="share-another-social-networks">  
    <?php echo $this->partial('share-to-social-networks.phtml', array(
        'url'			=> $url,
        'url_facebook'	=> $url_facebook,
        'furl'          => $furl,
        'durl'          => $durl,
        'id_page'       => $this->id_page,
        'id_user'		=> $this->id_user?$this->id_user:ID_USER_CHEAT_FOR_COUNT_SHARE,
        'show_text'		=> true,
        'message'		=> YouNet_Util::escapeForJs(sprintf($this->translate('REQUEST_MESSAGE_CONTEST'), $this->contest->title, $this->contest->getPageName($this->id_page))),
        'send'			=> false,
        'show_faces'	=> false,
        'show_fb_like'	=> false,
        'contest_name'  => $this->contest->title,
        'page_url'      => $_SERVER['HTTP_HOST'].$this->pageUrl(),
        'title'         => $info['title'],
        'description'   => nl2br($this->escape($this->contest->description)), 
        'invite_url'    => $this->contest->getInviteUrlSocialNetworks(array()),
        'is_contest'    => TRUE,
    ));?>
</div>


<?php if($this->contest->isAllowedComment()):?>
    <?php echo $this->social->render('comment',
        array(
            'url' => $this->social->getShareUrl('/contest/share/contest/id_page/'.$this->social->getIdPage().'/id_contest/'.$this->contest->id),
            'width' => 810
            
        ))
    ?>
    <script type="text/javascript">
        $(document).ready(function(){
            var ajax_url = '<?php echo $this->baseUrl('/contest/index/notify')?>';
            var data = {
                url: "<?php echo $this->social->getShareUrl('/contest/share/contest/id_page/'.$this->social->getIdPage().'/id_contest/'.$this->contest->id); ?>",
                id_contest: "<?php echo $this->contest->id?>",
                'is_contest': '1'
            };
            Social.handleCommentNotify(ajax_url, data);
        });
    </script>
<?php endif;?>
<?php 
if ('view' == $this->target):
	echo $this->partial('index/scrollTop.phtml'); 
endif;
?>